package lockstrategy;

import java.util.concurrent.Semaphore;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 74646
 * Date: 2022-05-28
 * Time: 23:54
 */
public class Demo4 {
    public static void main(String[] args) {
        // 初始化的值表示可用资源的个数
        Semaphore semaphore = new Semaphore(4);
        try {
            //申请资源( P 操作)
            semaphore.acquire();
            // 一次申请了两个资源
            semaphore.acquire(2);
            //释放资源( V 操作)
            semaphore.release();
            //一次释放了两个资源
            semaphore.release(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
